package com.yang.frost.blueberry.controller;

import com.yang.frost.blueberry.config.annotation.Log;
import com.yang.frost.blueberry.mapper.CmsCategoryMapper;
import com.yang.frost.blueberry.params.CmsArticlePageOrderParam;
import com.yang.frost.blueberry.params.CmsCategoryPageOrderParam;
import com.yang.frost.blueberry.params.CmsCategoryParam;
import com.yang.frost.blueberry.service.CmsCategoryService;
import com.yang.frost.blueberry.util.ApiResult;
import com.yang.frost.blueberry.util.Object2MapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author 10296
 * @date 2021/3/10
 * @Description: 类目管理
 */
@RestController
@RequestMapping("/cms/category")
@Api(value = "类目管理API", tags = {"类目管理"})
public class CmsCategoryController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private CmsCategoryService cmsCategoryService;


    @Log("类目管理--类目列表查询")
    @PostMapping("/qryArticleList")
    @ApiOperation(value = "类目管理--类目列表查询", notes = "类目管理--分页查询类目列表")
    public ApiResult qryCategoryList(@RequestBody CmsCategoryPageOrderParam articleParam, HttpServletResponse response) {
        logger.info(articleParam + "");
        Map<String, Object> paramsMap = Object2MapUtil.objectToMap(articleParam);

        return cmsCategoryService.qryCategoryList(paramsMap);
    }

    @Log("类目管理--查询类目树")
    @PostMapping("/qryCategoryNodeTree")
    @ApiOperation(value = "类目管理--类目树查询", notes = "类目管理--类目树")
    public ApiResult qryCategoryNodeTree(@RequestBody CmsCategoryPageOrderParam articleParam, HttpServletResponse response) {
        logger.info(articleParam + "");
        Map<String, Object> paramsMap = Object2MapUtil.objectToMap(articleParam);

        return cmsCategoryService.qryCategoryNodeTree(paramsMap);
    }

    @Log("类目管理--新增类目")
    @PostMapping("/insertCategory")
    @ApiOperation(value = "类目管理--新增类目", notes = "类目管理--新增类目")
    public ApiResult insertCategory(@RequestBody CmsCategoryParam categoryParam, HttpServletResponse response) {
        logger.info(categoryParam + "");
        Map<String, Object> paramsMap = Object2MapUtil.objectToMap(categoryParam);
        return cmsCategoryService.insertCategory(paramsMap);
    }

    @Log("类目管理--修改类目")
    @PostMapping("/updateCategory")
    @ApiOperation(value = "类目管理--类目树查询", notes = "类目管理--类目树")
    public ApiResult updateCategory(@RequestBody CmsCategoryParam categoryParam, HttpServletResponse response) {
        logger.info(categoryParam + "");
        Map<String, Object> paramsMap = Object2MapUtil.objectToMap(categoryParam);

        return cmsCategoryService.updateCategory(paramsMap);
    }

    @Log("类目管理--删除类目")
    @PostMapping("/deleteCategory")
    @ApiOperation(value = "类目管理--删除类目", notes = "类目管理--删除类目")
    public ApiResult deleteCategory(@RequestParam String categoryId, HttpServletResponse response) {
        logger.info(">>>>>>>>>>需要删除条目信息的ID>>>>>>>>" + categoryId);

        return cmsCategoryService.deleteCategory(categoryId);
    }


}
